function getImgHeight(imgSrc){
    var newImg = new Image();
    newImg.src = imgSrc;
    var height = newImg.height;
    //alert(height);
    return height;
}
function getImgWidth(imgSrc){
    var newImg = new Image();
    newImg.src = imgSrc;
    var width = newImg.width;
    //alert(width);
    return width;
}
    
function refresh(f){
    var cap = document.getElementById(f);
    cap.innerHTML = "<img src='cimage?a=" + Math.random() + "'/>";
}

function thumb(id, max_width, path) {    
    if(path != "null") {
        path = "items/" +path;
        var loader = new ImageLoader(path);
        loader.loadEvent = function(url, img){   
            var image = new Image();
            image.onload = function() {               
                height = image.height;
                width = image.width;
                
                if( height > width){ 
                    ratio = height/max_width;								
                    $(id).width = width/ratio;
                    $(id).height = max_width;
                } else {
                    ratio = width/max_width;								
                    $(id).height = height/ratio;
                    $(id).width = max_width;
                }
            }
            image.src = img.src;
            
            document[id].src = img.src
        }
        loader.load();
    } else {
        document[id].src = "images/no_photo.jpg";
        $(id).width = 120;
        $(id).height = 120;
    }
        
    /*/
        var image = new Image();
        image.onload=function(){                
            //alert("finish load");
            document[id].src = image.src
            height = image.height;
            width = image.width;
                
            if( height > width){ 
                ratio = height/max_width;								
                $(id).width = width/ratio;
                $(id).height = max_width;
            } else {
                ratio = width/max_width;								
                $(id).height = height/ratio;
                $(id).width = max_width;
            }
            image = null;                
        };            
        image.src = "items/" +path;
        
    } else {
        document[id].src = "images/no_photo.jpg";
        $(id).width = 160;
        $(id).height = 120;
    }*/
}
    
//orginally call scale_image by sum
function thumb2(image_id, limit){	
    var image = new Image();
    image.src = $(image_id).src;
    //	alert(imgSrc);
    image_height = image.height;
    image_width = image.width;
	
    //	alert(image_height);
    //	alert(image_width);

    if(image_height > image_width){
        $(image_id).height = limit;
        $(image_id).width = (image_width/image_height) * limit;
        //	alert('H>W');
    }else{
        $(image_id).width = limit;
        $(image_id).height = (image_height/image_width) * limit;
        //	alert('else');
    }
}

function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?"));
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
} 
    
//================ Image Loader ================

// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
    bubbling = bubbling || false;
    if(window.addEventListener)	{ // Standard
        element.addEventListener(type, expression, bubbling);
        return true;
    } else if(window.attachEvent) { // IE
        element.attachEvent('on' + type, expression);
        return true;
    } else return false;
}

var ImageLoader = function(url){
    this.url = url;
    this.image = null;
    this.loadEvent = null;
};

ImageLoader.prototype = {
    load:function(){
        this.image = document.createElement('img');
        var url = this.url;
        var image = this.image;
        var loadEvent = this.loadEvent;
        addListener(this.image, 'load', function(e){
            if(loadEvent != null){
                loadEvent(url, image);
            }
        }, false);
        this.image.src = this.url;
    },
    getImage:function(){
        return this.image;
    }
};
// ===================================================
    